<?php
	header ('Content-type: text/html; charset=UTF-8'); 

	include ('../config/validacao.php');
	$sigla = '';
	$nomeSecretaria = '';
	$idsecretaria = 0;
	
	if(isset($_GET['id'])){
	
		include ('../config/conexao.php');
	

		// query the database table for zip codes that match 'term'
		$rs = mysql_query('SELECT idsecretaria, sigla, nomeSecretaria FROM secretaria WHERE idsecretaria="'.$_GET['id'].'"');

		// loop through each zipcode returned and format the response for jQuery
		$dados = mysql_fetch_array($rs);
		
		$idsecretaria = $dados['idsecretaria'];
		$sigla = utf8_encode($dados['sigla']);
		$nomeSecretaria = utf8_encode($dados['nomeSecretaria']);
		
	}else{
		echo "<script>alert('Erro ao listar registro');</script>";
		echo "<script>window.location.href = 'e_secretaria.php';</script>";
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"http://www.w3.org/TR/html4/strict.dtd">
<html lang="pt_BR">
<head>
	<meta charset="iso-8859-1">
	<link rel="icon" type="image/png" href="../images/icone.png">
	<title><?php include('../titulo.php')?></title>
	<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
 	
	<link rel="stylesheet" href="../css/jquery-ui-1.8.21.custom.css" type="text/css" media="all" />
	<link rel="stylesheet" href="../css/index.css"  media="screen"> 
	<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"  media="screen"> 
	
	<script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script> 
	<script type="text/javascript" src="../js/bootstrap-inputmask.js"/></script>
	
    <script type="text/javascript" src="../js/jquery.validate.min.js"></script> 
	<script type="text/javascript" language="javascript" >
		$(document).ready(function(){
			$('#form').validate({  
				rules: {  
					sigla: { required: true },
					secretaria: { required: true }
					
				},  
				messages: {  
					sigla: { required: 'Preencha o campo'},
					secretaria: { required: 'Preencha o campo'}
				},  
				submitHandler: function( form ){  
					var dados = $( form ).serialize();  
					$.ajax({  
						type: "POST",  
						url: "update_secretaria.php",  
						data: dados,  
						success: function( data )  
						{  
							alert( data );
							window.location.href = "e_secretaria.php";
						}  
					});  
	  				return false;  
				}  
			}); 
		}); 
	</script>

	
</head>
<body onload="$('#consulta').select()">
	<div id="container">
		<div id="topo" style="text-align:left;position:absolute;">
			<?php include('../cabecalho.php') ?>
		</div>
		<br><br>
		<div id="body">
			<form id="form">
				<fieldset>
				<legend>Editar Local</legend>
				<label>Sigla</label>
				<input type="hidden" name="idsecretaria" value="<?php echo $idsecretaria;?>" />
				<input  class="input-small" type="text"  name="sigla" value="<?php echo $sigla;?>" onChange="javascript:this.value=this.value.toUpperCase();"/>
				<label>Nome local</label>
				<input class="input-xxlarge" type="text" name="nomesecretaria" value="<?php echo $nomeSecretaria;?>" onChange="javascript:this.value=this.value.toUpperCase();"/>
				<br>
				<button type="submit" class="btn">Atualizar</button>
				</fieldset>
				</form>
		</div>
<center>
<div style="width:900px">
<table style="font-size: 10px;" cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
	<thead>
		<th width="30%">Ramal</th>
		<th>Tag</th>
<!--		<th>Delete</th> -->
	</thead>
	<tbody>
	<?php
	        header ('Content-type: text/html; charset=ISO-8859-1');

		$rs = mysql_query('SELECT `nomeSetor`, `tag` FROM `setor` WHERE secretaria_idsecretaria = '.$_GET["id"]);
		if ( $rs && mysql_num_rows($rs) )
		{
			while( $row = mysql_fetch_array($rs) )
			{
							echo "<tr class='odd gradeX'>";
							echo "<td>".utf8_encode($row['nomeSetor'])."</td>";
							echo "<td>".utf8_encode($row['tag'])."</td>";
							//echo "<td>deletar</td>";
							//echo "<td><img src='../images/trash.png' ></td>";
							echo "</tr>";
			}
		}
	?>
	</tbody>
</table>
</div>
<center>


	</div>
</body>
</html>
